<?

$indexes = array (
	title=>array (label=>"Title",order=>"DEFAULT",wrapper=>"vmc_icon_task",callback=>"_template_list_substring",length=>26),
	lead_user=>array (label=>"Task Lead",order=>"DEFAULT",wrapper=>"vmc_icon_user"),
	total_time=>array (label=>"Total Time",order=>"DEFAULT",wrapper=>"vmc_icon_total_time"),
	status=>array (label=>"Status",order=>"DEFAULT",
			values=>array (
				"active"=>"Active",
				"inactive"=>"Inactive",
				"hold"=>"Hold",
				"suspended"=>"Suspended",
				"processing"=>"Processing",
				"new"=>"New",
				"assigned"=>"Assigned",
				"started"=>"Started",
				"stopped"=>"Stopped",
				"complete"=>"Complete",
			)),
	date_due=>array (label=>"Due Date",order=>"DEFAULT",wrapper=>"vmc_icon_date"),
	assignment_id=>array (label=>"Assignment",order=>"DEFAULT",callback=>"_app_task_assignment",
			values=>array (
				"assign"=>"<div class=\"vmc_icon_assign\">Assigned</div>",
				"reject"=>"<div class=\"vmc_icon_reject\">Rejected</div>",
				"forward"=>"<div class=\"vmc_icon_forward\">Forwarded</div>",
				"accept"=>"<div class=\"vmc_icon_accept\">Accepted</div>",
			)),
);

function _app_task_assignment ($container) {

	global $_GLOBAL_DBH;

	$row = $container->get_variable ("row");

	if ($row->status == "new") {

	print <<<HTML
<form action="/admin/projects/projects/fs_projects.php?fs_tab=tasks&project_id={$_REQUEST["project_id"]}&fs_tab_option=fs_tasks&fs_action=view&fs_tab_tasks=assignment&task_id={$container->get_variable ("value")}&fs_action_assignment=addnew&fs_tab_option_tasks=fs_assignment&pta_status=assign" method="POST"><td class="vmc_list_control_column_a vmc_list_button" align="center"><input type="submit" class="vmc_list_option vmc_button_assign" value="Assign Task"></td></form>

HTML;
	} else {
	
		$task_assignment = $_GLOBAL_DBH->query ("SELECT status FROM project_task_assignment WHERE task_id={$row->id} AND close='false'");
		$task_assignment = $_GLOBAL_DBH->fetch_object ($task_assignment);
		$column = $container->get_variable ("column");

		print <<<HTML
<td class="vmc_list_control_column_a">{$column["values"][$task_assignment->status]}</td>
HTML;
	}
}

$object_ctl = "/admin/projects/projects/fs_projects.php?fs_tab=tasks&project_id={$_REQUEST["project_id"]}&fs_tab_option=fs_tasks&fs_action=view&";
$link_options = "&fs_action=view&fs_tab=tasks&project_id={$_REQUEST["project_id"]}";
$list_options = array (
	array (
		label=>"Create A Tasks",
		link=>"fs_projects.php?fs_tab=tasks&project_id={$_REQUEST["project_id"]}&fs_tab_option=fs_tasks&fs_action=addnew"
	),
);

$_OBJECT_IFACE_LIST = _app_create_list_object (array (
                db_conn=>$_GLOBAL_DBH,
                indexes=>$indexes,
		list_count=>"SELECT COUNT(*) FROM project_tasks WHERE project_id={$_REQUEST["project_id"]}",
		list_select=>"
		SELECT project_tasks.*,project_tasks.id AS assignment_id,
			(SELECT CONCAT(last,', ',first)
				FROM users
				WHERE id=assigned_id)
			AS lead_user,
			/* (SELECT CASE current_id WHEN '0' THEN 'Unassigned' ELSE CONCAT(last,', ',first) END
				FROM users
				WHERE id=current_id)
			AS current_user, */
			(SELECT SEC_TO_TIME(SUM(
					CASE project_task_timer.date_end
						WHEN '' THEN UNIX_TIMESTAMP()
						ELSE UNIX_TIMESTAMP(project_task_timer.date_end)
					END - UNIX_TIMESTAMP(project_task_timer.date_begin)))
				FROM project_task_timer
				WHERE task_id=project_tasks.id)
			AS total_time
		FROM project_tasks
		WHERE project_id={$_REQUEST["project_id"]}",
                list_id=>"lc_project_task_tproject",
		list_title=>"&nbsp;&raquo;&nbsp;Project Tasks",
                list_options=>$list_options,
                primary_key=>"id",
                primary_relation=>"task_id",
                link_options=>$link_options,
                object_ctl=>$object_ctl
));

$_OBJECT_IFACE_TABBING_PANEL->insert_container ($_OBJECT_IFACE_LIST);

?>
